package com.ys.web.pay.manager;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.ys.base.BaseConstants;
import com.ys.utils.base.http.McodeHandler;
import com.ys.utils.base.j2se.*;
import com.ys.utils.help.GroupUtils;
import com.ys.utils.help.UserUtils;
import com.ys.utils.pay.PasswordHelper;
import com.ys.utils.pay.Result;
import com.ys.web.pay.PayEnum;
import com.ys.web.pay.PayService;
import com.ys.web.pay.model.UserAccount;
import com.ys.web.pay.model.UserAccountFlow;
import com.ys.web.pay.model.po.WalletBase;
import com.ys.web.user.login.LoginInfo;
import com.ys.web.ws.bean.MessageRequestBean;
import com.ys.web.ws.bean.MessageResponseBean;
import com.ys.web.ws.send.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Date;

@Component
public class PayManager {

    @Autowired
    private PayService payService;
    @Autowired
    private MessageService messageService;

    private static PayService _payService;
    private static MessageService _messageService;

    @PostConstruct
    void init() {
        _messageService = this.messageService;
        _payService = this.payService;
    }

    public static final String ORDERNO_PREFIX_DEPOSIT = "BANK_DEP_";

    public static boolean validatePayPassword(String payPassword, LoginInfo loginInfo) {
        String encryptPayPass = PasswordHelper.encryptPassword(payPassword, loginInfo.getSalt());
        return loginInfo.getPayPass().equals(encryptPayPass);
    }

    public static Result<?> accountModify(long userId, PayEnum.AccountFlowType type, long amount, String remark,int payChannel) {
        // 2.业务处理
        UserAccount userAccount = _payService.getAccountByUserId(userId);
        if (StringHandler.isEmpty(userAccount)) {
            userAccount = new UserAccount();
            userAccount.setUserId(userId);
            userAccount.setBalance(0L);
            userAccount.setFreezeAmount(0L);
            _payService.initUserAccount(userAccount);
        }
        if (amount <= 0) {
            Logger.error(type.getName() + "：金额非法:" + amount);
            return Result.newFailure(-6, "金额非法");
        }
        long balanceBefore = userAccount.getBalance(); // 动账前余额
        if ((type.getCode().equals(PayEnum.AccountFlowType.TYPE_RED_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.TYPE_TRANSFER_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.COUPON_BUY.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.PAY_ORDER.getCode()))
                && amount > balanceBefore) {
            Logger.error(type.getName() + "：账户余额不足:" + amount);
            return Result.newFailure(-5, "账户余额不足！");
        }
        long afterBalance = calBalance(balanceBefore, type.getCode(), amount);// 动账后余额
        long freezeAmountBefore = userAccount.getFreezeAmount();// 动账前冻结金额
        long freezeAmountAfter = calFreeze(freezeAmountBefore, type.getCode(), amount);// 动账后冻结金额
        long payAmount = payAmount(type.getCode(), amount);
        // 3.添加动账明细
        UserAccountFlow flow = new UserAccountFlow();
        flow.setUserId(userId);
        flow.setType(type.getCode());
        flow.setAmount(StringHandler.fenToYuan(StringHandler.getString(amount)));
        flow.setBalanceBefore(StringHandler.fenToYuan(StringHandler.getString(balanceBefore)));
        flow.setBalanceAfter(StringHandler.fenToYuan(StringHandler.getString(afterBalance)));
        flow.setFreezeAmountBefore(StringHandler.fenToYuan(StringHandler.getString(freezeAmountBefore)));
        flow.setFreezeAmountAfter(StringHandler.fenToYuan(StringHandler.getString(freezeAmountAfter)));
        flow.setFlag(getFlag(type));
        flow.setRemark(remark);
        flow.setPayChannel(payChannel);
        _payService.userAccountFlow(flow);
        // 4.修改账户余额
        UserAccount account = new UserAccount();
        account.setId(userAccount.getId());
        account.setBalance(afterBalance);
        account.setFreezeAmount(freezeAmountAfter);
        account.setOldBalance(userAccount.getBalance());
        account.setOldFreezeAmount(userAccount.getFreezeAmount());
        account.payAmount = payAmount;
        int i = _payService.userAccountUpdate(account);
        if (i != 1) {
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            Logger.error(type.getName() + "：修改账户信息失败:" + JSON.toJSONString(account));
//            return Result.newFailure(-1, "事务回滚！");
            return Result.newFailure(-1, "修改账户信息失败！");
        }
        return Result.newSuccess();
    }
    public static Result<?> accountModifyZfb(long userId, PayEnum.AccountFlowType type, long amount, String remark) {
        // 2.业务处理
        UserAccount userAccount = _payService.getAccountZfbByUserId(userId);
        if (StringHandler.isEmpty(userAccount)) {
            userAccount = new UserAccount();
            userAccount.setUserId(userId);
            userAccount.setBalance(0L);
            userAccount.setFreezeAmount(0L);
            _payService.initUserAccountZfb(userAccount);
        }
        if (amount <= 0) {
            Logger.error(type.getName() + "：金额非法:" + amount);
            return Result.newFailure(-6, "金额非法");
        }
        long balanceBefore = userAccount.getBalance(); // 动账前余额
        if ((type.getCode().equals(PayEnum.AccountFlowType.TYPE_RED_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.TYPE_TRANSFER_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.COUPON_BUY.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.PAY_ORDER.getCode()))
                && amount > balanceBefore) {
            Logger.error(type.getName() + "：账户余额不足:" + amount);
            return Result.newFailure(-5, "账户余额不足！");
        }
        long afterBalance = calBalance(balanceBefore, type.getCode(), amount);// 动账后余额
        long freezeAmountBefore = userAccount.getFreezeAmount();// 动账前冻结金额
        long freezeAmountAfter = calFreeze(freezeAmountBefore, type.getCode(), amount);// 动账后冻结金额
        long payAmount = payAmount(type.getCode(), amount);
        // 3.添加动账明细
        UserAccountFlow flow = new UserAccountFlow();
        flow.setUserId(userId);
        flow.setType(type.getCode());
        flow.setAmount(StringHandler.fenToYuan(StringHandler.getString(amount)));
        flow.setBalanceBefore(StringHandler.fenToYuan(StringHandler.getString(balanceBefore)));
        flow.setBalanceAfter(StringHandler.fenToYuan(StringHandler.getString(afterBalance)));
        flow.setFreezeAmountBefore(StringHandler.fenToYuan(StringHandler.getString(freezeAmountBefore)));
        flow.setFreezeAmountAfter(StringHandler.fenToYuan(StringHandler.getString(freezeAmountAfter)));
        flow.setFlag(getFlag(type));
        flow.setRemark(remark);
        flow.setPayChannel(3);
        _payService.userAccountFlow(flow);
        // 4.修改账户余额
        UserAccount account = new UserAccount();
        account.setId(userAccount.getId());
        account.setBalance(afterBalance);
        account.setFreezeAmount(freezeAmountAfter);
        account.setOldBalance(userAccount.getBalance());
        account.setOldFreezeAmount(userAccount.getFreezeAmount());
        account.payAmount = payAmount;
        int i = _payService.userZfbAccountUpdate(account);
        if (i != 1) {
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            Logger.error(type.getName() + "：修改账户信息失败:" + JSON.toJSONString(account));
//            return Result.newFailure(-1, "事务回滚！");
            return Result.newFailure(-1, "修改账户信息失败！");
        }
        return Result.newSuccess();
    }

    public static Result<?> accountModifyHjzf(long userId, PayEnum.AccountFlowType type, long amount, String remark) {
        // 2.业务处理
        UserAccount userAccount = _payService.getAccountHjzfByUserId(userId);
        if (StringHandler.isEmpty(userAccount)) {
            userAccount = new UserAccount();
            userAccount.setUserId(userId);
            userAccount.setBalance(0L);
            userAccount.setFreezeAmount(0L);
            _payService.initUserAccountHjzf(userAccount);
        }
        if (amount <= 0) {
            Logger.error(type.getName() + "：金额非法:" + amount);
            return Result.newFailure(-6, "金额非法");
        }
        long balanceBefore = userAccount.getBalance(); // 动账前余额
        if ((type.getCode().equals(PayEnum.AccountFlowType.TYPE_RED_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.TYPE_TRANSFER_SEND.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.COUPON_BUY.getCode()) ||
                type.getCode().equals(PayEnum.AccountFlowType.PAY_ORDER.getCode()))
                && amount > balanceBefore) {
            Logger.error(type.getName() + "：账户余额不足:" + amount);
            return Result.newFailure(-5, "账户余额不足！");
        }
        long afterBalance = calBalance(balanceBefore, type.getCode(), amount);// 动账后余额
        long freezeAmountBefore = userAccount.getFreezeAmount();// 动账前冻结金额
        long freezeAmountAfter = calFreeze(freezeAmountBefore, type.getCode(), amount);// 动账后冻结金额
        long payAmount = payAmount(type.getCode(), amount);
        // 3.添加动账明细
        UserAccountFlow flow = new UserAccountFlow();
        flow.setUserId(userId);
        flow.setType(type.getCode());
        flow.setAmount(StringHandler.fenToYuan(StringHandler.getString(amount)));
        flow.setBalanceBefore(StringHandler.fenToYuan(StringHandler.getString(balanceBefore)));
        flow.setBalanceAfter(StringHandler.fenToYuan(StringHandler.getString(afterBalance)));
        flow.setFreezeAmountBefore(StringHandler.fenToYuan(StringHandler.getString(freezeAmountBefore)));
        flow.setFreezeAmountAfter(StringHandler.fenToYuan(StringHandler.getString(freezeAmountAfter)));
        flow.setFlag(getFlag(type));
        flow.setRemark(remark);
        flow.setPayChannel(5);
        _payService.userAccountFlow(flow);
        // 4.修改账户余额
        UserAccount account = new UserAccount();
        account.setId(userAccount.getId());
        account.setBalance(afterBalance);
        account.setFreezeAmount(freezeAmountAfter);
        account.setOldBalance(userAccount.getBalance());
        account.setOldFreezeAmount(userAccount.getFreezeAmount());
        account.payAmount = payAmount;
        int i = _payService.userHjzfAccountUpdate(account);
        if (i != 1) {
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            Logger.error(type.getName() + "：修改账户信息失败:" + JSON.toJSONString(account));
//            return Result.newFailure(-1, "事务回滚！");
            return Result.newFailure(-1, "修改账户信息失败！");
        }
        return Result.newSuccess();
    }


    public static String getFlag(PayEnum.AccountFlowType type) {
        String flag = "";
        switch (type) {
            case TYPE_RECHARGE:
            case TYPE_RED_RECV:
            case TYPE_RED_EXPR:
            case WITHDRAWAL_FAIL:
            case TYPE_TRANSFER_RECV:
            case TYPE_TRANSFER_EXPR:
            case POPULARIZE:
            case PAY_ORDER_MONEY_REFUND:
            case WITHDRAWAL_UNDO:
                flag = PayEnum.projectFlowStyle.INCOME.getCode();
                break;
            case APPLY_FOR_WITHDRAWAL:
            case TYPE_TRANSFER_SEND:
            case TYPE_RED_SEND:
            case PAY_ORDER:
            case PAY_ORDER_MONEY:
            case COUPON_BUY:
                flag = PayEnum.projectFlowStyle.DISBURSE.getCode();
                break;
        }
        return flag;
    }

    // 计算余额
    public static long calBalance(long beforeBalance, String type, long amount) {
        long resultBalance = beforeBalance;
        if (PayEnum.AccountFlowType.INCOME.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_UNDO.getCode().equals(type)
                || PayEnum.AccountFlowType.APPLY_FAIL_WITHDRAWAL.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_RECHARGE.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_RED_RECV.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_RED_EXPR.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_TRANSFER_RECV.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_TRANSFER_EXPR.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_FAIL.getCode().equals(type)
                || PayEnum.AccountFlowType.POPULARIZE.getCode().equals(type)
                || PayEnum.AccountFlowType.PAY_ORDER_MONEY.getCode().equals(type)
                || PayEnum.AccountFlowType.PAY_ORDER_MONEY_FREE.getCode().equals(type)
                || PayEnum.AccountFlowType.PAY_ORDER_MONEY_REFUND.getCode().equals(type)) {
            resultBalance = resultBalance + amount;//增加余额
        } else if (PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode().equals(type)
                || PayEnum.AccountFlowType.PLAT_WITHDRAWAL_SUCCESS.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_RED_SEND.getCode().equals(type)
                || PayEnum.AccountFlowType.TYPE_TRANSFER_SEND.getCode().equals(type)
                || PayEnum.AccountFlowType.COUPON_BUY.getCode().equals(type)
                || PayEnum.AccountFlowType.PAY_ORDER.getCode().equals(type)) {
            resultBalance = resultBalance - amount;//减少余额
        }
        return resultBalance;
    }

    // 计算冻结金额
    public static long calFreeze(long beforeFreeze, String type, long amount) {
        long resultFreeze = beforeFreeze;
        if (PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode().equals(type)) {
            resultFreeze = resultFreeze + amount;//增加冻结金额
        } else if (PayEnum.AccountFlowType.WITHDRAWAL_SUCCESS.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_UNDO.getCode().equals(type)
                || PayEnum.AccountFlowType.APPLY_FAIL_WITHDRAWAL.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_FAIL.getCode().equals(type)) {
            resultFreeze = resultFreeze - amount;//减少冻结金额
        }
        return resultFreeze;
    }
    // 计算冻结金额
    public static long payAmount(String type, long amount) {
        if (PayEnum.AccountFlowType.APPLY_FOR_WITHDRAWAL.getCode().equals(type)) {
            return amount;//增加冻结金额
        } else if (PayEnum.AccountFlowType.WITHDRAWAL_SUCCESS.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_UNDO.getCode().equals(type)
                || PayEnum.AccountFlowType.APPLY_FAIL_WITHDRAWAL.getCode().equals(type)
                || PayEnum.AccountFlowType.WITHDRAWAL_FAIL.getCode().equals(type)) {
            return - amount;//减少冻结金额
        }
        return amount;
    }
    public static boolean send(Long uid, WalletBase walletBase, String redId) {
        String messageId = IdUtil.randomUUID().toUpperCase();
        MessageRequestBean messageRequestBean;
        boolean flag = false;
        try {
            messageRequestBean = getMessageRequestBean(uid, walletBase, redId, walletBase.getType(), messageId);
            flag = true;
            //先给发送者推送
            MessageResponseBean messageResponseBean = getMessageResponseBean(
                    messageRequestBean.getMessageId(), messageRequestBean.getFrom(), BaseConstants.SINGLE_PREFIX + messageRequestBean.getTo(),
                    messageRequestBean.getAvatarUrl(), messageRequestBean.getUserName(), messageRequestBean.getData(), messageRequestBean.getCreateTime(),
                    messageRequestBean.getCode(), messageRequestBean.getWidth(), messageRequestBean.getHeight(), null,walletBase.payChannel
            );
            messageResponseBean.setPayChannel(walletBase.payChannel);
            if (walletBase.getGp().equals("1")) {
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.SINGLE_PREFIX + messageRequestBean.getTo());
            } else {
                messageResponseBean.setGroupId(walletBase.getReceivedId());
                messageResponseBean.setGroupPic(GroupUtils.getCacheGroupInfo(walletBase.getReceivedId()).getPic());
                messageResponseBean.setGroupName(UserUtils.getGroupCacheNameByGroupId(walletBase.getReceivedId()));
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
            }
            //后给接收者推送
            if (walletBase.getGp().equals("1")) {
                _messageService.sendMessageUser(messageRequestBean,-1);
            } else {
                messageRequestBean.setGroupId(walletBase.getReceivedId());
                _messageService.sendMessageGroup(messageRequestBean);
            }
            return true;
        } catch (Exception e) {
            Logger.error("组装转账回调推送消息异常：", e);
            MessageResponseBean messageResponseBean = new MessageResponseBean();
            messageResponseBean.setMessageId(flag ? messageId : "");
            messageResponseBean.setCode(walletBase.getType());
            messageResponseBean.setData(JsonUtil.toJson(MapHandler.initMap("status", flag ? "发送失败" : "网络异常")));
            if (walletBase.getGp().equals("1")) {
                messageResponseBean.setWindowId(BaseConstants.SINGLE_PREFIX + McodeHandler.to32Radix(Long.parseLong(walletBase.getReceivedId())));
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.SINGLE_PREFIX + McodeHandler.to32Radix(Long.parseLong(walletBase.getReceivedId())));
            } else {
                messageResponseBean.setWindowId(BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
            }
            //发送失败退回金额
            return false;
        }
    }


    public static boolean send(Long uid, WalletBase walletBase, String redId, String messageId) {
        MessageRequestBean messageRequestBean;
        boolean flag = false;
        try {
            messageRequestBean = getMessageRequestBean(uid, walletBase, redId, walletBase.getType(), messageId);
            flag = true;
            //先给发送者推送
            MessageResponseBean messageResponseBean = getMessageResponseBean(
                    messageRequestBean.getMessageId(), messageRequestBean.getFrom(), BaseConstants.SINGLE_PREFIX + messageRequestBean.getTo(),
                    messageRequestBean.getAvatarUrl(), messageRequestBean.getUserName(), messageRequestBean.getData(), messageRequestBean.getCreateTime(),
                    messageRequestBean.getCode(), messageRequestBean.getWidth(), messageRequestBean.getHeight(),null,walletBase.payChannel
            );
            messageResponseBean.setPayChannel(walletBase.payChannel);
            if (walletBase.getGp().equals("1")) {
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.SINGLE_PREFIX + messageRequestBean.getTo());
            } else {
                messageResponseBean.setGroupId(walletBase.getReceivedId());
                messageResponseBean.setGroupPic(GroupUtils.getCacheGroupInfo(walletBase.getReceivedId()).getPic());
                messageResponseBean.setGroupName(UserUtils.getGroupCacheNameByGroupId(walletBase.getReceivedId()));
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
            }
            //后给接收者推送
            if (walletBase.getGp().equals("1")) {
                 _messageService.sendMessageUser(messageRequestBean,-1);
            } else {
                messageRequestBean.setGroupId(walletBase.getReceivedId());
                _messageService.sendMessageGroup(messageRequestBean);
            }
            return true;
        } catch (Exception e) {
            Logger.error("组装转账回调推送消息异常：", e);
            MessageResponseBean messageResponseBean = new MessageResponseBean();
            messageResponseBean.setMessageId(flag ? messageId : "");
            messageResponseBean.setCode(walletBase.getType());
            messageResponseBean.setData(JsonUtil.toJson(MapHandler.initMap("status", flag ? "发送失败" : "网络异常","amount",StringHandler.fenToYuan(walletBase.getAmount()))));
            if (walletBase.getGp().equals("1")) {
                messageResponseBean.setWindowId(BaseConstants.SINGLE_PREFIX + McodeHandler.to32Radix(Long.parseLong(walletBase.getReceivedId())));
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.SINGLE_PREFIX + McodeHandler.to32Radix(Long.parseLong(walletBase.getReceivedId())));
            } else {
                messageResponseBean.setWindowId(BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
                GroupUtils.sendIfAbsent(messageResponseBean, String.valueOf(uid), BaseConstants.GROUP_PREFIX + walletBase.getReceivedId());
            }
            //发送失败退回金额
            return false;
        }
    }


    private static MessageRequestBean getMessageRequestBean(Long uid, WalletBase walletBase, String redId, Integer code, String messageId) {
        LoginInfo cacheUser = UserUtils.getCacheUser(uid);
        MessageRequestBean messageRequestBean = new MessageRequestBean();
        String toId = walletBase.getGp().equals("1") ? walletBase.getReceivedId() : walletBase.getReceivedIds();
        messageRequestBean.setCode(code);
        messageRequestBean.setWidth(200.00);
        messageRequestBean.setHeight(80.00);
        messageRequestBean.setFrom(McodeHandler.to32Radix(uid));
        messageRequestBean.setCreateTime(DateHandler.getDate(new Date(), BaseConstants.BASE_FORMAT));
        messageRequestBean.setAvatarUrl(cacheUser.getAvatarUrl());
        messageRequestBean.setMessageId(messageId);
        messageRequestBean.setData(JsonUtil.toJson(MapHandler.initMap("serialNumber", redId
                        , "remark", walletBase.getRemark(), "status", "已发送"
                        , "showType", "1"
                        , "toId", walletBase.getGp().equals("1") ? McodeHandler.to32Radix(Long.parseLong(toId)) : toId
                        , "amount", StringHandler.fenToYuan(walletBase.getAmount())
                        , "avatarUrl", cacheUser.getAvatarUrl(), "nickName", cacheUser.getNickName()
                        , "receiveIds", StringHandler.isNotEmpty(walletBase.getReceivedIds()) && walletBase.getGp().equals("2") ? walletBase.getReceivedIds() : ""
                )));
        if(StringHandler.isNotEmpty(walletBase.payChannel))
            messageRequestBean.payChannel = walletBase.payChannel;
        messageRequestBean.setUserName(cacheUser.getNickName());
        messageRequestBean.setTo(walletBase.getGp().equals("1") ? McodeHandler.to32Radix(Long.parseLong(walletBase.getReceivedId())) : walletBase.getReceivedId());
        return messageRequestBean;
    }

    public static MessageResponseBean getMessageResponseBean(String messageId, String fromId, String windowId, String avatarUrl, String userName, String data, String createTime,
                                                             Integer code, Double width, Double height, String clientId,int payChannel) {
        MessageResponseBean result = new MessageResponseBean();
        result.setMessageId(messageId);
        result.setFrom(fromId);
        result.setWindowId(windowId);
        result.setCreateTime(createTime);
        result.setAvatarUrl(avatarUrl);
        result.setUserName(userName);
        result.setData(data);
        result.setCode(code);
        result.setHeight(height);
        result.setWidth(width);
        result.setPayChannel(payChannel);
        return result;
    }
}
